package com.example.springkotlindemo.controller

import com.example.springkotlindemo.entity.MyTest
import com.example.springkotlindemo.mapper.MyTestMapper
import com.example.springkotlindemo.model.AjaxResult
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.reactor.mono
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import reactor.core.publisher.Mono
import java.time.LocalDateTime

/**
 * @author Xu Haidong
 * @date 2023/4/25 10:40
 */
@RestController
@RequestMapping("/myTest2")
class MyTest2Controller {

    private val logger = LoggerFactory.getLogger(this.javaClass)

    @Autowired
    private lateinit var mapper: MyTestMapper

    @GetMapping("/start")
    fun start(): AjaxResult {
        val test = MyTest()
        test.name = "张三"
        test.createTime = LocalDateTime.now()
        logger.info("开始新增")
        mapper.insertMyTest(test)
        val id = test.id
        logger.info("开始查询id=$id")
        mapper.selectMyTestById(id)
        logger.info("开始修改")
        val update = MyTest()
        update.name = "李四"
        update.id = id
        mapper.updateMyTest(update)
        logger.info("开始删除")
        mapper.deleteMyTestById(id)
        return AjaxResult.success()
    }
}